package Ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;

public class PropertyPage extends AbsPersonalPage {

	public PropertyPage(String resumeId, HttpServletRequest request) {
		super(resumeId, request);
		mStrSubClassName = "resumeproperty";
	}

	@Override
	public void execSql(Statement stmt, HttpServletRequest request)
			throws SQLException {
		if (bCreate) {
			return;
		}

		if (bSubmit) {
			String sql = "UPDATE resume SET "
					+ "resume_prop = " + request.getParameter("property")
					+ ", resumetype = " + request.getParameter("resumetype")
					+ ", resume_name = '" + request.getParameter("resuemname")
					+ "' WHERE id = " + mResumeId;

			stmt.executeUpdate(sql);

			return;
		}

		if (bDelete) {
			return;
		}
		
		String sql = "SELECT resume.lang, resume.visit_count, resume.resume_name, resume.resume_prop, resume.resumetype, cate_resumetype.list_name FROM resume LEFT JOIN cate_resumetype ON resume.resumetype = cate_resumetype.id WHERE resume.id = " + mResumeId;

		rs = stmt.executeQuery(sql);
	}

	@Override
	protected void writeWithoutCreate(PrintWriter writer) throws SQLException {
		if (rs == null || !rs.next()) {
			return;
		}

		final boolean lang = rs.getBoolean("resume.lang");
		final boolean prop = rs.getBoolean("resume.resume_prop");

		writer.print("<form action=\"ResumeSys?action=personal&amp;option=resume&amp;extent=property&amp;info=" + mResumeId + "&amp;submit=1\" name=\"wane_resume\" method=\"post\" target=\"ajaxform\" onsubmit=\"return resumeproperty();\">");
		writer.println("<table cellpadding=\"0\" cellspacing=\"0\" class=\"formtable\"><caption><h2>简历基本信息</h2></caption><tr><th width=\"100\">语种:</th>");
		writer.println("<td width=\"160\"><strong>" + (lang ? "中文" : "英文") + "</strong></td><th width=\"100\">浏览:</th>");
		writer.print("<td><strong>" + rs.getInt("resume.visit_count") + "</strong> 次</td></tr>");
		writer.print("<tr><th>简历名称:</th><td colspan=\"3\"><input type=\"text\" name=\"resuemname\" class=\"t_input\" value=\"");
		writer.print(rs.getString("resume.resume_name") + "\" /></td></tr></table>");

		writer.print("<table cellpadding=\"0\" cellspacing=\"0\" class=\"formtable\">");

		writer.print("<caption><h2>属性</h2></caption><tr><th width=\"100\"><input name=\"property\" type=\"radio\" value=\"1\" ");

		if(prop == true)
		{
			writer.print("checked=\"checked\"");
		}

		writer.print(" /> 属性: 公开</th><td>您的简历可以被全部企业用户查看</td></tr><tr><th><input name=\"property\" type=\"radio\" value=\"0\" ");

		if(prop == false)
		{
			writer.print("checked=\"checked\"");
		}

		writer.print(" /> 属性: 隐藏</th><td>企业用户不可以查看您的简历详情</td></tr><tr><th>简历类别</th><td><span class=\"floatr\">用人单位可按此分类快速准确地找到您的简历</span>");

		writer.print("<a href=\"#\" onclick=\"category.load('tresumetype','resumetype',document.wane_resume.resumetype.value);return false;\"><span id=\"tresumetype\">");
		writer.print(rs.getString("cate_resumetype.list_name"));
		writer.print("</span></a><input type=\"hidden\" id=\"resumetype\" name=\"resumetype\" value=\"" + rs.getInt("resume.resumetype") + "\" />");

		writer.println("</td></tr><tr><th>&nbsp;</th><td><input type=\"submit\" name=\"Submit\" value=\"保存修改\" class=\"submit\" />");
		writer.println("<input type=\"button\" name=\"nextstep\" value=\"跳到下一步\" onclick=\"resumeload('iter')\" class=\"button\" /></td></tr></table></form>");
	}

	@Override
	protected void writeWithCreate(PrintWriter writer) throws IOException {
		// TODO Auto-generated method stub
		
	}

}
